﻿using System.Linq;

namespace Sustainalytics.Utils
{
    // usage :  public HttpResponseMessage Get( [FromUri] HttpGetOptions options)
    public class ListOptions
    {
        public static ListOptions Default
        {
            get
            {
                return new ListOptions();
            }
        }

        public ListOptions()
        {
            this.Skip = 0;
            this.Take = 100;
            this.IncludeAllFields = false;
            this.GetCount = false;
            this.OrderAscending = true;
            this.OrderBy = null;
        }

        public int Skip { get; set; }

        public int Take { get; set; }

        public bool IncludeAllFields { get; set; }

        public bool GetCount { get; set; }

        public bool OrderAscending { get; set; }

        public string[] OrderBy { get; set; }

        protected void Fill(ListOptions options)
        {
            if (options == null)
            {
                return;
            }

            this.Skip = options.Skip;
            this.Take = options.Take;
            this.IncludeAllFields = options.IncludeAllFields;
            this.OrderAscending = options.OrderAscending;
            this.GetCount = options.GetCount;

            this.OrderBy = options.OrderBy != null ? options.OrderBy.Select(a => a).ToArray() : null;
        }
    }
}